package lhb.test.SC.configuration.web;

import java.util.HashMap;
import java.util.Iterator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConfigController {
	
	@Autowired
	ConfigurableEnvironment env;
	
	@RequestMapping("props")
	public Object getEnv() {
		Iterator<PropertySource<?>> it = env.getPropertySources().iterator();
		
		StringBuffer sb = new StringBuffer();
		String[] profiles = env.getActiveProfiles();
		for (String profile : profiles) {
			sb.append(profile).append(",");
		}
		sb.append("\n");
		while(it.hasNext()) {
			sb.append(it.next()).append("\n");
		}
		return sb;
	}
	
	@RequestMapping("name")
	public Object getName() {
		return env.getProperty("name");
	}
}
